package com.anti.jdbc.core.storeprocedure;
import com.anti.commom.constant.ExpEnumConstant;
import com.anti.commom.core.exception.BusinessException;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description TODO
 * @Author anTi
 * @Date 2020-10-6
 */
public class SpParamTypeMapping {
    private static final Map<Class, Integer> typeMap = new HashMap();

    public SpParamTypeMapping() {
    }

    public static int getSqlType(Class clz) {
        Integer type = typeMap.get(clz);
        if (type == null) {
            throw new BusinessException(ExpEnumConstant.SERVER_EXCEPTION_ENUM,"暂不支持的参数类型:" + clz.getName());
        } else {
            return type;
        }
    }

    static {
        typeMap.put(String.class, 12);
        typeMap.put(Byte.class, -7);
        typeMap.put(Integer.class, 4);
        typeMap.put(Short.class, 5);
        typeMap.put(Long.class, -5);
        typeMap.put(Date.class, 91);
        typeMap.put(java.sql.Date.class, 91);
        typeMap.put(BigDecimal.class, 3);
        typeMap.put(Float.class, 6);
        typeMap.put(Double.class, 8);
        typeMap.put(Byte[].class, 2004);

        try {
            typeMap.put(Integer.TYPE, 4);
            typeMap.put(Short.TYPE, 5);
            typeMap.put(Long.TYPE, -5);
            typeMap.put(Double.TYPE, 8);
            typeMap.put(Float.TYPE, 6);
            typeMap.put(Byte.TYPE, -7);
        } catch (Exception var1) {
        }

    }
}
